from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By


# 打开浏览器
driver = webdriver.Chrome()
driver.get('https://weibo.com/')
sleep(2)
# 窗口最大化
driver.maximize_window()
sleep(2)
# 点击登录/注册
driver.find_element(By.XPATH, '/html/body/div[1]/div[2]/div[2]/div[2]/main/div[2]/div/div/div[2]/div[1]/div/button').click()
sleep(2)
# 窗口切换
driver.switch_to.window(driver.window_handles[-1])
sleep(2)
# 点击账号登录
# driver.find_element(By.CLASS_NAME, 'hidden.md:inline').click()
driver.find_element(By.XPATH, '/html/body/div[1]/div/div/div[2]/div[2]/ul/li[2]/a/span[2]').click()
sleep(2)
# 输入账号
driver.find_element(By.XPATH, '/html/body/div[1]/div/div/div[2]/div[2]/form/div[1]/input').send_keys('15985645480')
sleep(2)
# 输入密码
driver.find_element(By.XPATH, '/html/body/div[1]/div/div/div[2]/div[2]/form/div[2]/input').send_keys('12345678Aa')
sleep(2)
# 点击登录按钮
driver.find_element(By.XPATH, '/html/body/div[1]/div/div/div[2]/div[2]/button').click()
sleep(10)
